# -*- coding:utf8 -*-

__author__ = 'Administrator'

from socket import *
import time

def server_socket():

    s = socket(AF_INET, SOCK_STREAM)
    s.bind(('', 8888))
    s.listen(5)

    while True:
        client, addr = s.accept()
        print "Got a connection from %s " % str(addr)
        timestr = time.ctime(time.time()) + "\r\n"
        client.send(timestr.encode('ascii'))
        client.close()

def client_socket():
    s = socket(AF_INET, SOCK_STREAM)
    s.connect(('localhost', 8888))
    tm = s.recvfrom(1024)
    print ("Time time is %s" % tm.decode('ascii'))

if __name__ == "__main__":
    server_socket()

    client_socket()
